#pragma once

#include <iostream>
#include <string>

const int default_backlog = 5;

class Socket
{
public:
    Socket() {}
    virtual void create() = 0;
    virtual void bind(uint16_t port) = 0;
    virtual void listen(int backlog) = 0;
    virtual void connect(std::string& serverIp, uint16_t serverPort) = 0;
    virtual Socket* accept(std::string* peerIp, uint16_t* peerPort) = 0;
    virtual int getSocketFd() = 0;
    virtual void setSocketFd(int socketFd) = 0;
    virtual ~Socket() {}
public:
    void createListenSocket(uint16_t port, int backlog = default_backlog)
    {
        create();
        bind(port);
        listen(backlog);
    }

    void createConnectSocket(std::string& serverIp, uint16_t serverPort)
    {
        create();
        connect(serverIp, serverPort);
    }

    void createNormalSocket(int socketFd)
    {
        setSocketFd(socketFd);
    }
};